<?php

namespace common\components\rest;

use common\components\ActiveRecord;
use Yii;

class CreateAction extends \yii\rest\CreateAction
{

    /**
     * @inheritdoc
     */
    public function run()
    {
        Yii::info("为{$this->modelClass}执行REST/create动作,参数:" . json_encode(
                Yii::$app->getRequest()->getBodyParams(),
                JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), __METHOD__);

        /** @var ActiveRecord $model */
        $model = parent::run();
        if ( ! empty($model->getErrors()))
        {
            Yii::warning("为{$this->modelClass}创建记录时出错:" . $model->formatErrors(), __METHOD__);
        }

        return $model;
    }
}
